from django.shortcuts import render
from app.models import Goods_info
# Create your views here.


def main_page(request):
    return render(request, 'index.html')


def search(request):
    return render(request, 'search.html')


def myinfo(request):
    return render(request, 'myinfo.html')


def detail(request):
    """
    详细信息
    :param request:
    :return:
    """
    goods_id = request.GET.get('id')
    if goods_id:
        goods_id = str(goods_id)
    else:
        goods_id = 1
    goods_info = Goods_info.objects.filter(pk=goods_id)
    if goods_info:
        good_info = goods_info[0]
    else:
        goods_info = Goods_info.objects.filter(pk=1)
        good_info = goods_info[0]
    texts = good_info.g_text_infos.split('^')
    context = {
        'goods_name': good_info.g_name,
        'img_src': good_info.g_img_src,
        'now_price': good_info.g_now_price,
        'old_price': good_info.g_old_price,
        'text1': texts[0],
        'text2': texts[1],
        'text3': texts[2],
        'text4': texts[3],
        'rank_info': good_info.g_rank_info,

    }
    return render(request, 'detail.html', context=context)
